
import axios from "axios";
axios.defaults.baseURL = "http://192.168.227.190:8890/maintenance";

axios.interceptors.request.use(
  function (config) {
    // 1.从缓存里面取token
    let token = sessionStorage.getItem("token");
    // 2.如果有token就在请求头里设置token
    // config.headers.token = token 请求头里面的token内容
    token && (config.headers.token = token);
    return config;
  }, function (error) {
    return Promise.reject(error);
});

axios.interceptors.response.use(function (response) {
    return response;
  }, function (error) {
      switch(error.response.status){
          case 401://token有问题
              sessionStorage.clear()
              alert('重新登录');
              window.location.href='/'
              break;
            case 405:
                alert('没有权限');
                break;
      }
return Promise.reject(error);
});

export default axios;
